package com.ipay.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class JedisExecutor {
	@Autowired
	private JedisManager jedis;
	public void setValue(JedisKeyPrefix prefix, String key, String value){
		jedis.setValue(this.getKey(prefix, key), value);
	}
	
	public void setValue(JedisKeyPrefix prefix, String key, String value, int expire){
		jedis.setValue(this.getKey(prefix, key), value, expire);
	}
	
	public String getValue(JedisKeyPrefix prefix, String key){
		return jedis.getValue(this.getKey(prefix, key));
	}
	
	public String remove(JedisKeyPrefix prefix, String key){
		return jedis.remove(this.getKey(prefix, key));
	}
	public void setObj(JedisKeyPrefix prefix, String key, JedisEntity value){
		jedis.setObj(this.getKey(prefix, key), value);
	}
	
	public void setObj(JedisKeyPrefix prefix, String key, JedisEntity value, int expire){
		jedis.setObj(this.getKey(prefix, key), value, expire);
	}
	
	public JedisEntity getObj(JedisKeyPrefix prefix, String key){
		return jedis.getObj(this.getKey(prefix, key));
	}
	
	public void removeObj(JedisKeyPrefix prefix, String key){
		jedis.remove(this.getKey(prefix, key));
	}
	
	private String getKey(JedisKeyPrefix prefix, String key) {
		return prefix.value() + key;
	}
}
